"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.generateHtml = void 0;
const templates_1 = require("./templates");
const tools_1 = require("./tools");
const fs = require("fs");
const path = require("path");
function generateHtml(option) {
    const { inputValue = "" } = option;
    const inputPathList = inputValue.split("/").filter(Boolean);
    const inputPath = path.join(process.cwd(), ...inputPathList);
    if (!fs.statSync(inputPath).isFile() && !inputValue.endsWith(".js")) {
        throw new Error("input should be a .js file");
    }
    inputPathList.pop();
    option.outputValue = option.outputValue || inputPathList.join("/");
    const { svgList } = (0, tools_1.getIconfontContent)(inputPath);
    outputFile(svgList, option);
}
exports.generateHtml = generateHtml;
// 输出index.html文件
function outputFile(svgList, options) {
    const { outputValue } = options;
    const outputPath = (0, tools_1.getOutputPath)(outputValue, "index.html", ".html");
    const html = (0, templates_1.generateHtmlContent)(svgList.map((item) => item.name));
    fs.writeFileSync(outputPath, html);
}
